package com.ruoyi.web.controller.manage;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: wwy
 * @Date: 2021/1/5 15:18
 */
@Api("门户端退出")
@RestController
@RequestMapping("/api")
public class AppLogoutController {
    @Autowired
    private TokenService tokenService;
    /**
     * 退出
     * @return
     */
    @ApiOperation("门户端退出接口")
    @PostMapping("/logout")
    public AjaxResult logOut(HttpServletRequest request){
        //获取当前登录用户的信息
        //进行token验证
        LoginUser loginUser = tokenService.getLoginUser(request);
        String token = loginUser.getToken();
        tokenService.delLoginUser(token);
        return AjaxResult.success();
    }
}
